package com.ewing.utils;

import org.apache.axis.utils.StringUtils;

import com.ewing.common.utils.SystemPropertyUtils;

/**
 * 文件URL转换工具类
 * 
 * @author tansonlam
 * @createDate 2016年2月26日
 * 
 */
public class FileUrlUtil {

	/**
	 * 转成资源相关的路径
	 * 
	 * @param relativePath
	 * @return
	 */
	public static String convertResourceUrl(String relativePath) {
		if (StringUtils.isEmpty(relativePath))
			return null;
		if (StringUtils.isEmpty(SystemPropertyUtils.getResourceWebsite()))
			return relativePath;
		else
			return SystemPropertyUtils.getResourceWebsite() + relativePath;
	}

	/**
	 * 转换成商店相关的URL
	 * 
	 * @param relativePath
	 * @return
	 */
	public static String convertShopUrl(String relativePath) {
		if (StringUtils.isEmpty(relativePath))
			return null;
		if (StringUtils.isEmpty(SystemPropertyUtils.getShopDomain()))
			return relativePath;
		else
			return SystemPropertyUtils.getShopDomain() + relativePath;
	}

	public static String concatPath(String... content) {
		StringBuffer sb = new StringBuffer();

		for (int i = 0; i < content.length; i++) {
			sb.append(content[i]);
			if (i < content.length - 1)
				sb.append("/");
		}
		String path = sb.toString();
		return path.replace("://", "@@@").replace("//", "/")
				.replace("@@@", "://");
	}

	public static void main(String[] args) {
		System.out.println(concatPath("http://www.kuaidmai.com", "index"));
	}
}
